/**
 * Desenvolvido pela Fábrica de Software do CESUPA.
 * Todos os direitos reservados.
 */
package br.cesupa.fabsoft.nomedoprojeto.system.application.facades;

import br.cesupa.fabsoft.nomedoprojeto.system.application.CommonWebOperations;
import java.io.File;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;

/**
 * Exposes a unified interface to the application operations.
 *
 * @author Breno Leite
 */
public class ApplicationFacade {

    /**
     * @return a utilitary to perform common operations on web applications
     * @see CommonWebOperations
     */
    public static CommonWebOperations performWebOperation() {
        return new CommonWebOperations();
    }

    /**
     * @return services offered by the application
     * @see ServicesFacade
     */
    public static ServicesFacade getServicesFacade() {
        return new ServicesFacade();
    }

    /**
     * @return a facade to operations related to the view
     * @see ViewFacade
     */
    public static ViewFacade getViewFacade() {
        return new ViewFacade();
    }

    /**
     * @return a facade to traslate resources used by the application
     * @see TranslationFacade
     */
    public static TranslationFacade getTranslationFacade() {
        return new TranslationFacade();
    }

    /**
     * @return a facade to manipulate beans managed by the Java Server Faces
     * @see ManagedBeanFacade
     */
    public static ManagedBeanFacade getManagedBeanFacade() {
        return new ManagedBeanFacade();
    }

    /**
     * Retrieves the path of this application ewb directory.
     *
     * @return the application web directory path
     */
    public static String getWebDirectoryPath() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ServletContext servletContext =
                (ServletContext) facesContext.getExternalContext().getContext();

        return servletContext.getRealPath("");
    }

    /**
     * Retrives the full path of a directory present on the web directory.
     *
     * @param directory the name of the directory to be searched
     * @return the full path to the given drectory
     */
    public static String getDirectoryOnWebPath(final String directory) {

        FacesContext facesContext = FacesContext.getCurrentInstance();
        ServletContext servletContext =
                (ServletContext) facesContext.getExternalContext().getContext();

        return servletContext.getRealPath(File.separator + directory);
    }
}
